#include "messageinfomation.h"
#include "ui_messageinfomation.h"
#include <transtext.h>
#include <QGraphicsEffect>

MessageInfomation::MessageInfomation(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MessageInfomation)
{
    ui->setupUi(this);
    setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
    setAttribute(Qt::WA_ShowModal, true);
    setAttribute(Qt::WA_TranslucentBackground);
    QGraphicsDropShadowEffect *windowShadow = new QGraphicsDropShadowEffect(this);
    // 阴影多少，留出部分阴影的空间
    windowShadow->setBlurRadius(24);
    windowShadow->setOffset(0);
    ui->frame->setGraphicsEffect(windowShadow);
    ui->frame->setStyleSheet("QFrame { background-color: white; border-radius: 8px; }");
    ui->labelTitle->setText(TransString::instance()->uninstallTitle);
    initData();
    initConnection();
}

MessageInfomation::~MessageInfomation()
{
    delete ui;
}

void MessageInfomation::initData() {
    switch (m_messageType) {
        case kProgramRunning:
        ui->label_content->setText(TransString::instance()->uninstallRunning);
        ui->okBtn->setVisible(true);
        ui->okBtn->setText(TransString::instance()->uninstallOK);
        ui->cancelBtn->setVisible(false);
        break;
    default:
        break;
    }
}

void MessageInfomation::display(const emMessageBoxType type, const QPoint parentPoint, const QSize parentSize)
{
    m_messageType = type;
    initData();
    move(QPoint(parentPoint.x() + (parentSize.width() - width()) / 2, parentPoint.y() + (parentSize.height() - height()) / 2));
    show();
}

void MessageInfomation::initConnection()
{
    connect(ui->okBtn, &QPushButton::clicked, this, [this](){
        hide();
        emit signalCloseType(m_messageType, kOk);
    });

    connect(ui->cancelBtn, &QPushButton::clicked, this, [this](){
        hide();
        emit signalCloseType(m_messageType, kCancel);
    });

    connect(ui->messageClose, &QPushButton::clicked, this, [this](){
        hide();
        emit signalCloseType(m_messageType, kClose);
    });
}
